import wx from 'wx';
import api from '@/api/api';

const request =(url, data = {}, method = 'GET')=> {
  return new Promise(function (resolve, reject) {
    wx.request({
      url: url,
      data: data,
      method: method,
      header: {
        'Content-Type': 'application/json',
        // 'X-Xbyjshop-Token': wx.getStorageSync('token')
      },
      success: (res)=> {
        // console.log('请求成功，url:', url);
        // console.log('请求参数，data:', data);
        if (res.statusCode === 200) {
          resolve(res.data);
        }else{
          reject(res.errMsg);
        }

      },
      fail: (err)=> {
        reject(err)
        // console.log('请求失败，url', url);
        // console.log('请求参数，data:', data);
      }
    })
  });
}

export default {
  request
}
